//
//  JobViewController.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/2/25.
//  Copyright © 2017年 金橙云. All rights reserved.
//
#define WIDTH self.view.bounds.size.width
#define HEIGHT self.view.bounds.size.height
#import "JobViewController.h"


#import "TabHederView.h"
#import "JobCustomCell.h"
#import "GenViewController.h"//待跟进
#import "YuViewController.h"//逾期
#import "QianYueViewController.h"//首付待催款
#import "QianKuanViewController.h"//待签约
#import "HuiViewController.h"//按揭回款
#import "TodoHttpManager.h"

#import "MJRefresh.h"

#import "UILabel+LXAdd.h"

@interface JobViewController ()<UITableViewDelegate,UITableViewDataSource,TabHederViewDelagate>

{
 
    NSMutableArray *_firstArr;//数据源数组
    NSMutableDictionary *_firstDataDic;
    NSArray *_cellArr;
    NSArray *_imgArr;
    NSString *_paiStr;//当前排名
    NSString *nowTime;
    NSString *wanStr;
    NSString *zongStr;
    NSString *biStr;
    NSArray *_liDataArr;
    NSString *genCountStr;
    NSString *yuCStr;
    NSString *qianCStr;
    NSString *qYueStr;
    NSString *huiStr;
    NSMutableArray *_shuArr;
    
}

@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) TabHederView *hederView;
@property(nonatomic,strong)NSMutableArray *countArr;//返回的每个组的个数


@end

@implementation JobViewController

-(TabHederView *)hederView{
    if (_hederView) {
        return _hederView;
    }
    
    _hederView = [[TabHederView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 260) ];
    
    _hederView.delegate = self;
    
    [self.tableView reloadData];
    _hederView.backgroundColor = BgColor;
    
    [self.view addSubview:_hederView];
    return _hederView;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"工作任务";
    self.view.backgroundColor = BgColor;
    [self.navigationItem setHidesBackButton:YES];
    _liDataArr = [NSArray array];
    _firstDataDic = [NSMutableDictionary dictionaryWithCapacity:0];
    _manager = [TodoHttpManager sharedManager];

    _cellArr = [NSArray arrayWithObjects:@"待跟进",@"逾期未跟进",@"首付待催款",@"待签约",@"按揭未回款", nil];
    _countArr = [[NSMutableArray alloc] init];
    _imgArr =[NSArray arrayWithObjects:@"img_gen",@"img_yu",@"img_qian",@"img_qianyue",@"img_huikuan", nil];
    _shuArr = [NSMutableArray arrayWithObjects:@"1",@"2",@"222",@"333",@"444",@"555", nil];

   [self.view addSubview:self.tableView];
 
}

-(UITableView *)tableView{
    
    if (_tableView) {
        return _tableView;
    }
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0, [UIScreen mainScreen].bounds.size.width
,[UIScreen mainScreen].bounds.size.height-LL_TabbarHeight) style:UITableViewStyleGrouped];
    _tableView.backgroundColor = BgColor;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.rowHeight = 50;
    _tableView.tableHeaderView = self.hederView;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        self.hederView.isrefresh = YES;
    }];
 
    return _tableView;
}

-(void)setDelegate:(NSMutableDictionary *)Dic
{
    
    [self refreshTabWithDic:Dic];
    
}

- (void)refreshTabWithDic:(NSMutableDictionary *)Dic{
    _firstDataDic = Dic;
    genCountStr = [[_firstDataDic objectForKey:@"genjin"] objectForKey:@"count"];
    
    yuCStr = [[_firstDataDic objectForKey:@"yuqi"] objectForKey:@"count"];
    qianCStr = [[_firstDataDic objectForKey:@"sf_cui"] objectForKey:@"count"];
    qYueStr = [[_firstDataDic objectForKey:@"go_sign"] objectForKey:@"count"];
    huiStr = [[_firstDataDic objectForKey:@"aj_hk"] objectForKey:@"count"];;
    
    _countArr = [NSMutableArray arrayWithObjects:genCountStr,yuCStr,qianCStr,qYueStr,huiStr, nil];
    
    [self.tableView reloadData];
    [self.tableView.mj_header endRefreshing];
  
    
}

#pragma mark - tableViewDelegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *cellIndetifier = @"cell";
    JobCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndetifier];
    if (cell== nil) {
        cell = [[JobCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndetifier];
    }
    
    cell.imageView.image = [UIImage imageNamed:_imgArr[indexPath.row]];

    cell.textLabel.font = [UIFont systemFontOfSize:14];
    if (_countArr.count != 0)
    {
        NSString *arrStr = _cellArr[indexPath.row];
        NSString *countStr = [NSString stringWithFormat:@" %@ 组",_countArr[indexPath.row]];
        NSString *title = [arrStr stringByAppendingString:countStr];
        cell.textLabel.text =title;
        cell.textLabel.keywords =[NSString stringWithFormat:@"%@",_countArr[indexPath.row]];
        cell.textLabel.keywordsColor= OverColor;
        [cell.textLabel getLableSizeWithMaxWidth:300];

    }
           return cell;
}

#pragma mark - 设置分组的个数
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
#pragma mark - 设置分组的高度
- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 1.0;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 取消选中状态
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
 
    if (indexPath.row == 0)
    {
        GenViewController *genVC =[[GenViewController alloc] init];
        genVC.genConStr = genCountStr;
        genVC.genDataDic = [_firstDataDic objectForKey:@"genjin"];
        [self.navigationController pushViewController:genVC animated:NO];
    }
    else if (indexPath.row == 1)
    {
        YuViewController *yuVC = [[YuViewController alloc] init];
        yuVC.yuStr = yuCStr;
        yuVC.yuDic = [_firstDataDic objectForKey:@"yuqi"];
        [self.navigationController pushViewController:yuVC animated:NO];
    }
    else if (indexPath.row == 2)
    {
        QianKuanViewController *qianKuanVC =[[QianKuanViewController alloc] init];
        qianKuanVC.qianStr = qianCStr;
        qianKuanVC.qianDic = [_firstDataDic objectForKey:@"sf_cui"];
        [self.navigationController pushViewController:qianKuanVC animated:NO];
    }
    else if (indexPath.row == 3)
    {
        QianYueViewController *qianYueVC =[[QianYueViewController alloc] init];
        qianYueVC.yueStr = qYueStr;
        qianYueVC.yueDic = [_firstDataDic objectForKey:@"go_sign"];
        [self.navigationController pushViewController:qianYueVC animated:NO];
    }
    else
    {
        HuiViewController *huiVC = [[HuiViewController alloc] init];
        huiVC.huiKStr = huiStr;
        huiVC.huiKDic = [_firstDataDic objectForKey:@"aj_hk"];
        [self.navigationController pushViewController:huiVC animated:NO];
    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.1;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}

-(void)btnClick:(UIButton *)btn
{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
